<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">

	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">上级编号：</label>
								<div class="layui-input-block">
									<span id="sjid" style="line-height: 36px;"></span>
									<input type="hidden" name="fid" />
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">图标：</label>
								<div class="layui-input-block">
									<div class="layui-inline margin_bottom0">
										<input placeholder="选择文件上传" name="icon" class="layui-input" lay-verify="icon" />
									</div>
									<button type="button" class="layui-btn layui-btn-normal" id="choose">选择文件上传</button>
									<!-- <input type="text" name="hospital" placeholder="请输入采集医院" autocomplete="off" class="layui-input"> -->
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">名称：</label>
								<div class="layui-input-block">
									<input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">标题：</label>
								<div class="layui-input-block">
									<input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">目录：</label>
								<div class="layui-input-block">
									<input type="text" name="path" placeholder="请输入目录" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">模板：</label>
								<div class="layui-input-block">
									<input type="text" name="tpl" placeholder="请输入模板" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">链接：</label>
								<div class="layui-input-block">
									<input type="text" name="url" placeholder="请输入链接" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">备注：</label>
								<div class="layui-input-block">
									<input type="text" name="notes" placeholder="请输入备注" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">排序：</label>
								<div class="layui-input-block">
									<input type="text" name="oid" placeholder="请输入排序" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				fid: getParam('fid'),
				id: getParam('id'),
			}
			if(getParam('fid')){
				$('#sjid').html(getParam('fid'))
				$("input[name=fid]").val(getParam('fid'))
			}
			
			// console.log(_data.id);

			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate','upload'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					upload = layui.upload,
					laydate = layui.laydate,
					form = layui.form;

				// initdata();
				
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
				
					console.log(_data);
					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id){
							submitdata(server.editsubmodule);
						} else {
							submitdata(server.addsubmodule);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});
				
				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									console.log(parent.parent.window.location);
									parent.parent.initdata();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				
				//选完文件后不自动上传
				upload.render({
					elem: '#choose',
					url: server.upimg,
					// auto: false,
					// bindAction: '#choose',
					accept: 'file',
					before: function(){
						loading();
					},
					done: function(res) {
						console.log(res)
						if (res.file) {
							layer.msg('上传成功,请保存');
							_data.icon = res.file;
							$('input[name=icon]').val(res.file);
							closeloading();
						}
					}
				});
				
				function initdata() {
					$.get(server.querytestdetail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.orders_test
							
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
			});
		</script>
	</body>
</html>
